﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Agency_company_biaoshu_weijiaofei : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_Account != null)
        {
            if (_Account.Type == "1")
            {
                showgridview();
            }
            if (_Account.Type == "17")
            {
                return;
            }
        }
        else
        {
            Response.Write("<script>window.location.href='../HomePage/Default.aspx';</script>"); 
        }
    }
    protected void showgridview()
    {
        string strConditions;
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = " company c inner join account a on c.accountid=a.accountid  ";
        dbPage.Key = " c.accountid";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = " distinct accountname,companyname ";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 15;                                                    //没有显示记录条数   
        dbPage.OrderBy = " a.accountname";        //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键
    }
    public string fctConditions()
    {
        string strwhere = " a.accountname not in (select usercode_sc  from company_biaoshu) and (c.accountid in (select distinct accountid_sc from bid_Goods_TBR) or c.accountid in (select distinct accountid_tb from bid_Goods_TBR))";
        string usercode = TextBox1.Text.Trim();
        string username = TextBox2.Text.Trim();
        if (usercode != "")
        {
            strwhere += " and a.accountname like '%" + usercode + "%'";
        }
        if (username != "")
        {
            strwhere += " and c.companyname like '%" + username + "%'";
        }
        return strwhere;
    }
}
